<template>
  <div>
    <div class="header_search_nav search_form">
      <div class="ipt_left">
        <el-form ref="queryForm" :model="queryParams" label-width="150px">
          <el-row>
            <el-col :span="6">
              <el-form-item label="门店" prop="storeId">
                <el-select
                  v-model="queryParams.storeId"
                  placeholder="请选择"
                  filterable
                  @change="getLists"
                >
                  <el-option
                    v-for="(item, index) in $store.state.user.stores"
                    :key="index"
                    :label="item.name"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="内容类型" prop="contentType">
                <el-select
                  v-model="queryParams.contentType"
                  placeholder="请选择"
                  class="w-200"
                >
                  <el-option
                    v-for="item in contentTypeData"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <div class="timebox">
                <el-form-item label="日期时间" prop="date">
                  <timer
                    ref="timer"
                    :timer.sync="queryParams.date"
                    @query="handleQuery"
                    flag="TM"
                  ></timer>
                </el-form-item>
              </div>
            </el-col>
          </el-row>
        </el-form>
      </div>

      <div class="btn_right">
        <button class="btn1" @click="handleQuery">筛选</button>
        <button class="btn2" @click="resetQuery">重置</button>
      </div>
    </div>

    <!-- 所有列表 -->
    <div class="table_card">
      <!-- 上部分 title -->
      <div class="table_card_top">
        <span class="solid_left"></span>
        <div class="table_card_title">订单消费记录</div>
        <div class="op_right">
          <button
            class="primary_button"
            @click="handleExport"
            :loading="exportLoading"
          >
            导出订单
          </button>
        </div>
      </div>

      <div class="table_list">
        <el-table
          :data="tableList"
          stripe
          style="width: 100%"
          v-loading="loading"
        >
          <el-table-column prop="orderNo" label="订单编号" width="170">
          </el-table-column>
          <el-table-column prop="storeName" label="门店名称" width="150">
          </el-table-column>
          <el-table-column prop="userName" label="技师名称"> </el-table-column>
          <el-table-column prop="contentTypeStr" label="内容类型" width="100">
          </el-table-column>
          <el-table-column prop="contentName" label="内容名称">
          </el-table-column>

          <el-table-column prop="roomName" label="房间名称"> </el-table-column>

          <el-table-column prop="orderOpen" label="开房时间" width="170">
          </el-table-column>

          <el-table-column prop="clockTypeStr" label="上钟类型">
          </el-table-column>

          <el-table-column prop="payTypeStr" label="结算状态">
          </el-table-column>

          <el-table-column prop="serverCount" label="服务数量">
          </el-table-column>
          <el-table-column prop="serverPrice" label="服务价格">
          </el-table-column>
          <!-- <el-table-column prop="serverStatus" label="状态">
            <template slot-scope="scope">
              <div>{{ serverStatusObj[scope.row.serverStatus] }}</div>
            </template>
          </el-table-column> -->
        </el-table>
        <pagination
          :total="total"
          :page.sync="queryParams.pageNo"
          :limit.sync="queryParams.pageSize"
          @pagination="getLists"
        />
      </div>
    </div>
  </div>
</template>

<script>
import { getOrderServer, ExportOrderServer } from "@/api/bpm/orderHistory";
import { mapGetters } from "vuex";
import ClientInfo from "@/components/ClientInfo/clientInfo.vue";
import timer from "@/components/getTime/timer";

export default {
  name: "Storeadminclientlist",
  components: {
    ClientInfo,
    timer,
  },
  data() {
    return {
      loading: false,
      exportLoading: false,
      queryParams: {
        storeId: "",
        pageNo: 1,
        pageSize: 10,
        contentType: "", // 内容类型(I:项目;P:商品)
        orderNo: "", // 订单编号
        roomId: "", // 房间标识
        date: [],
        startTime: "", // 开房开始时间
        endTime: "", // 开房结束时间
      },
      total: 0,
      tableList: [],

      //   N:未报种;I:进行中;F:已下钟
      serverStatusObj: {
        N: "未报种",
        I: "进行中",
        F: "已下钟",
      },

      contentTypeData: [
        {
          value: "I",
          label: "项目",
        },
        {
          value: "P",
          label: "商品",
        },
      ],
    };
  },

  computed: {
    ...mapGetters(["userInfo"]),
  },

  mounted() {
    document.addEventListener("paste", function (e) {
      if (e.target.offsetParent.classList.contains("pwd")) {
        e.preventDefault();
      }
    });
  },

  methods: {
    handleExport() {
      const query = JSON.parse(JSON.stringify(this.queryParams));

      if (!!query.date) {
        query.startTime = this.queryParams.date[0];
        query.endTime = this.queryParams.date[1];
      }
      delete query.date;
      this.$modal
        .confirm("是否确认导出订单服务商品数据?")
        .then(() => {
          this.exportLoading = true;
          return ExportOrderServer(query);
        })
        .then((response) => {
          this.$download.excel(response, "订单服务商品");
          this.exportLoading = false;
        })
        .catch(() => {
          this.exportLoading = false;
        });
    },

    getLists() {
      this.loading = true;
      const query = JSON.parse(JSON.stringify(this.queryParams));

      if (!!query.date) {
        query.startTime = this.queryParams.date[0];
        query.endTime = this.queryParams.date[1];
      }
      delete query.date;
      getOrderServer(query)
        .then((res) => {
          console.log(res, "1");
          this.loading = false;
          const { code, data } = res;
          if (code === 0) {
            this.tableList = data.list;
            this.total = data.total;
          }
        })
        .catch((err) => {
          this.loading = false;
        });
    },

    // 筛选
    handleQuery() {
      this.getLists();
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.resetFormData("queryForm");
      this.handleQuery();
      this.getLists();
    },

    resetFormData(formName) {
      this.$refs[formName].resetFields();
    },
  },
};
</script>

<style lang="scss" scoped>
.pick-clien-style {
  .pick-client-head {
    display: flex;
    justify-content: space-between;
    margin-bottom: 20px;
    .input-left {
      width: 300px;
      position: relative;
      padding-right: 80px;
      .but {
        position: absolute;
        top: 0px;
        right: 0px;
      }
    }
  }

  .table-head {
    padding-left: 80px;
    height: 48px;
    background-color: #f7f8fa;
    line-height: 48px;
    font-size: 12px;
  }

  .pick-item-list {
    max-height: 500px;
    overflow-y: auto;
    .pick-item-style {
      border-bottom: solid 1px #f2f2f2;
      padding: 20px 0px 20px 36px;
    }
    .pick-item-center {
      width: 100%;
      display: flex;
      align-items: center;

      .user-style {
        font-size: 14px;

        .user-name {
          color: #3b98fe;
        }

        .span_small {
          font-size: 12px;
          color: #999999;
          margin-top: 8px;
        }
      }
    }
  }
}

.f-zero {
  font-size: 0px;
}
.table_list {
  .clients {
    cursor: pointer;
  }
}

.switch-style {
  display: inline-block;
  position: relative;
  &::before {
    position: absolute;
    width: 100%;
    content: "";
    height: 100%;
    z-index: 2;
    cursor: pointer;
  }
}

.client_name {
  color: #1890ff;
}

.checkBox {
  display: flex;
  margin-top: 12px;
}
</style>
